package com.wwe.kotlinstudy.example20

class Person {
    var name: String = "老炮儿"

    constructor(name: String) {
        this.name = name
    }

    //用companion关键字标识的对象即为伴生对象
    companion object Factory {
        var name: String = "Kotlin的工厂模式"
        fun setName(name: String): Factory {
            this.name = name;
            return this;
        }
        fun create(): Person = Person(name)
    }
}

fun test6() {
    var p = Person.setName("大尾巴").create()
    println(p.name)
}